package org.example.struct.array2;

import com.alibaba.fastjson2.JSON;

/**
 * @author liyishan
 * @date 2023/9/13 10:21
 * @apiNote
 */

public class Test00080RemoveDuplicates {

    public static void main(String[] args) {
        int[] nums = {1,1,1,2,2,3};
        test(nums);
        System.out.println(JSON.toJSON(nums));
    }

    public static int test(int[] nums) {
        int n = nums.length;
        if (n <= 2) {
            return n;
        }
        int slow = 2;
        int fast = 2;
        while(fast < n){
            if (nums[slow - 2] != nums[fast]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
